import {ElMessage, ElMessageBox} from "element-plus"
import {post} from "@/axios"
import {useUserStore} from "@/store";

export function verifyUserAuthority(){
    return new Promise((resolve, reject) => {
        const userStore = useUserStore()
        ElMessageBox.prompt("我们需要验证你的身份，请输入密码",'提示',{
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            inputPattern:
                /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*?/,
            inputPlaceholder:"请输入你的密码",
            inputType:"password",
        })
            .then(({ value }) => {
                post("/User/VerifyUserPassword",
                    {username:userStore.getUserInfo.username, password:value})
                    .then((res:any)=>{
                    if(res.status === 200){
                        resolve(true)
                    }else {
                        reject(false)
                    }
                })
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '你已取消了认证！',
                })
                reject(false)
            })
    })
}